package com.syedu.day13.homework1;

import com.syedu.util.InputUtil;

/**
 * description：
 * @author Administrator
 * @date 2022/3/28 9:38
 */
public class Client {
    public static void main(String[] args) {
        Ui ui = new Ui();
        StudentService service = new StudentServiceImpl();
        Student student;
        Long id = null;
        String name;
        Integer age;
        boolean result;
        boolean flag = true;
        while (flag) {
            ui.showMenu();
            int choice = InputUtil.getInt("请您选择功能:");
            switch (choice) {
                case 1:
                    //添加
                    name = InputUtil.getStr("请您输入学生姓名:");
                    age = InputUtil.getInt("请您输入学生年龄:");
                    student = new Student(name, age);
                    result = service.insertStudent(student);
                    if (result) {
                        System.out.println("学生添加成功!");
                    } else {
                        System.out.println("学生添加失败!");
                    }
                    break;
                case 2:
                    //删除
                    id = InputUtil.getLong("请您输入学生学号:");
                    result = service.deleteStudent(id);
                    if (result) {
                        System.out.println("学生删除成功!");
                    } else {
                        System.out.println("学生删除失败!");
                    }
                    break;
                case 3:
                    //修改
                    id = InputUtil.getLong("请您输入学生学号:");
                    name = InputUtil.getStr("请您输入学生姓名:");
                    age = InputUtil.getInt("请您输入学生年龄:");
                    service.updateStudent(id, name, age);
                    break;
                case 4:
                    //查看
                    service.selectAllStudents();
                    break;
                case 5:
                    //退出
                    flag = false;
                    break;
                default:
                    System.out.println("暂无该功能!");

            }
        }
    }
}